//
//  XDReconmmendTableViewCell.m
//  Le way walkers
//
//  Created by dlios on 15-5-13.
//  Copyright (c) 2015年 LTXZ. All rights reserved.
//

#import "XDReconmmendTableViewCell.h"
#import "XDRecommend.h"
#import "UIImageView+WebCache.h"
@interface XDReconmmendTableViewCell()
@property (nonatomic,retain) UILabel *lable1;
@property (nonatomic,retain) UILabel *lable2;
@property (nonatomic,retain) UILabel *lable3;
@property (nonatomic,retain) UILabel *lable4;
@property (nonatomic,retain) UIImageView *image1;
@property (nonatomic,retain) UIImageView *image;
@property (nonatomic,retain) UIImageView *image2;
@end
@implementation XDReconmmendTableViewCell
- (void)dealloc
{
    [_lable1 release];
    [_lable2 release];
    [_lable3 release];
    [_lable4 release];
    [_image1 release];
    [_image release];
    [_image2 release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.image = [[[UIImageView alloc]init]autorelease];
        self.image.layer.cornerRadius = 12;
        self.image.layer.masksToBounds = YES;
        [self.contentView addSubview:_image];
        
        
        self.lable1 = [[[UILabel alloc]init]autorelease];
        // _lable1.text = @"手把手教你在东京拍摄樱花";
        [_lable1 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17]];
        _lable1.textColor = [UIColor whiteColor];
        [_image addSubview:_lable1];
        //1设置label行数不限制
        _lable1.numberOfLines = 0;
        
        
        self.lable2 = [[[UILabel alloc]init]autorelease];
        //_lable2.text = @"2015.03.30 8天 7489次浏览";
        [_lable2 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:11]];
        _lable2.textColor = [UIColor whiteColor];
        [_image addSubview:_lable2];
        _lable2.numberOfLines = 0;
        
        
        self.lable3 = [[[UILabel alloc]init]autorelease];
        //_lable3.text = @"日本,东京";
        _lable3.textColor = [UIColor whiteColor];
        [_lable3 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:11]];
        [_image addSubview:_lable3];
        _lable3.numberOfLines = 0;
        
        
        self.lable4 = [[[UILabel alloc]init]autorelease];
        _lable4.textColor = [UIColor whiteColor];
        [_lable4 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
        [_image addSubview:_lable4];
        _lable4.numberOfLines = 0;
        
        
        self.image1 = [[[UIImageView alloc]init]autorelease];
        [_image1 setImage:[UIImage imageNamed:@"7.jpg"]];
        [_image addSubview:_image1];
        
        
        
        self.image2 = [[[UIImageView alloc]init]autorelease];
        _image2.layer.cornerRadius = 15;
        _image2.layer.masksToBounds = 15;
        [_image addSubview:_image2];
    
    }
    return self;
}




- (void)layoutSubviews
{
    [super layoutSubviews];
    _image.frame = CGRectMake(5, 5, self.contentView.frame.size.width-10, (self.contentView.frame.size.width - 10)/4*3);
//    _lable1.frame = CGRectMake(15, 10, self.contentView.frame.size.width-10, 30);
//    _lable2.frame = CGRectMake(20, 35, 200, 25);
//    _lable3.frame = CGRectMake(20, 47, 200, 25);
//    _lable4.frame = CGRectMake(50, 195, 150, 30);
    //设置cell上控件的frame
    CGFloat f = [[self class] heightWithText:_lable1.text];
    _lable1.frame = CGRectMake(15, 10, self.contentView.frame.size.width-30,f);
    CGFloat f1 = [[self class] heightWithText:_lable2.text];
    _lable2.frame = CGRectMake(20, 10+f, 200, f1);
    CGFloat f2 = [[self class] heightWithText:_lable3.text];
    _lable3.frame = CGRectMake(20, 10+f+f1-8, 200, f2);
    CGFloat f3 = [[self class] heightWithText:_lable4.text];
    _lable4.frame = CGRectMake(50, self.contentView.frame.size.height/1.2, 150, f3);
    _image1.frame = CGRectMake(13, 16+f, 5, 20);
    _image2.frame = CGRectMake(13, self.contentView.frame.size.height/1.2, 30, 30);
}
//2.根据字符串获取高度
+ (CGFloat)heightWithText:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont fontWithName:@"Helvetica-Bold" size:17]};
    CGSize size = CGSizeMake([UIScreen mainScreen].bounds.size.width-40, 500);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return  rect.size.height;
}


- (void)setRecommend:(XDRecommend *)recommend
{
    if (recommend != _recommend) {
        [_recommend release];
        _recommend = [recommend retain];
    }
   // [_image sd_setImageWithURL:[NSURL URLWithString:recommend.cover_image]];
    [_image sd_setImageWithURL:[NSURL URLWithString:recommend.cover_image] placeholderImage:[UIImage imageNamed:@"69E58PIChJC_1024.jpg"]];
    _lable1.text = recommend.name;
    NSString *str = [NSString stringWithFormat:@"%@ %@天",recommend.first_day,recommend.day_count];
    _lable2.text = str;
    _lable3.text = recommend.popular_place_str;
    NSString *str1 = [NSString stringWithFormat:@"by %@",[recommend.user objectForKey:@"name"]];
    _lable4.text = str1;
    [_image2 sd_setImageWithURL:[NSURL URLWithString:[recommend.user objectForKey:@"avatar_m"]]];
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
